import { requests } from "./request"
/**
 * 登录请求 scope：login.vue
 * @param {Json} data 
 * @returns 
 */
export const loginAxios =(json,thisa) =>{
  return  requests({
    url: "./Database-cyt/GrantController/login",
    data: json,
    method: "POST",
  }).then(function (response) {
    console.log("输出响应数据如下111:")
    console.log(Object.keys(response.data));
    let control = Object.keys(response.data)
    if(control[0]=="user"){
      thisa.$router.push("/user")
    }else if(control[0]=="master"){
      thisa.$router.push("/manager")
    }else{
      alert("账号密码不对,请注册")
    }
  });
}
/**
 * 获取用户信息方法 scope:login.vue
 * @param {Json} data 
 * @returns 
 */
export const getUserAxios = (data,thisa)=>{
  
  return  requests({
    url: "./Database-cyt/QueryController/queryAll",
    data: data,
    method: "POST",
  }).then(function (response) {
    console.log("进入到getUserAxios then中");
    console.log(response)
    thisa.data=response.data;
    thisa.$store.commit("setDat", response.data);
    console.log(thisa.$store.state.dat);
  });
}

export const registerAxios = (data,thisa) =>{
 return requests({
    url: "./Database-cyt/GrantController/register",
    data: data,
    method: "POST",
  })
    .then(function (response) {
        thisa.register=response.data;
        console.log(response.data)
        alert(Object.keys(response.data)[0]+":"+Object.values(response.data)[0])
        if(Object.keys(response.data)[0]=="success"){
          thisa.$router.push("/")
        }
    })
    .catch(function (error) {
      console.log("error");
      console.log(error);
    });
}


export const queryAxios=(data,thisa)=>{
  return requests({
    method: "POST",
    url: "./Database-cyt/QueryController/queryById",
    data:data,
  }).then(function (response) {
    thisa.query =response.data
    console.log(response);

  });
}

export const addPrivilegeAxios=(data)=>{
  
  return requests({
    method: "POST",
    url: "./Database-cyt/UserController/addPrivilege",
    data:data,
  }).then(function (response) {
    /* thisa.privilege =response.data */
    console.log("输出addPrivilegeAxios中response如下：")
    console.log(response);
   
  });
}

export const addAxios = (data,thisa)=>{
  return requests({
    method: "POST",
    url: "./Database-cyt/UserController/addUser",
    data:data,
  }).then(function (response) {
    thisa.privilege =response.data
    console.log(response);
    alert(Object.values(response.data)[0])
  });
}


export const deleteAxios = (data,thisa)=>{
  return requests({
    method: "POST",
    url: "./Database-cyt/UserController/deleteUser",
    data:data,
  }).then(function (response) {
    thisa.privilege =response.data
    console.log(response);
    alert(Object.values(response.data)[0])
  }); 
}

export const deletePrivilegeAxios =(data)=>{
  return requests({
    method: "POST",
    url: "./Database-cyt/UserController/deletePrivilege",
    data:data,
  }).then(function (response) {
    
    console.log(response);
  }); 
}

export const logoutAxios =(thisa)=>{
  return requests({
    method:"POST",
    url:"./Database-cyt/GrantController/logout",
    data:""
  }).then(function(response){
    console.log(response)
    thisa.$router.push("/");
    
  })
}

export const modifyAxios =(data,thisa)=>{
  return requests({
    method:"POST",
    url:"./Database-cyt/UserController/updateUser",
    data:data,
  }).then(function(response){
    console.log(response)
  
    
  })
}